﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;

namespace OAuth2Authorizer.Serialization
{
    internal class JsonSerializer<T> : ISerializer<T>
    {
        private DataContractJsonSerializer _serializer;

        internal JsonSerializer()
        {
            _serializer = new DataContractJsonSerializer(typeof(T));
        }

        public T ReadObject(Stream stream)
        {
            return (T)_serializer.ReadObject(stream);
        }

        public void WriteObject(Stream stream, T obj)
        {
            _serializer.WriteObject(stream, obj);
        }
    }
}
